package com.wing.product.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 产品明细表
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("pro_product_detail")
public class ProductDetail extends BaseEntity<ProductDetail> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 商品ID
     */
    private Long productId;

    /**
     * 商品SKU编码
     */
    private String skuCode;

    /**
     * 商品缩略图
     */
    private String productPic;

    /**
     * 商品SKU名称
     */
    private String skuName;

    /**
     * 商品规格列表
     */
    private String skuSpec;

    /**
     * 商品规格值列表
     */
    private String skuSpecValue;

    /**
     * 商品规格值名称列表
     */
    private String skuSpecValueNames;

    /**
     * 企业货号
     */
    private String enterpriceCode;

    /**
     * 市场指导价
     */
    private BigDecimal marketPrice;

    /**
     * 商品店铺价
     */
    private BigDecimal storePrice;

    /**
     * 最低活动价
     */
    private BigDecimal activityPrice;

    /**
     *渠道价
     */
    private BigDecimal spPrice;

    /**
     * 平台供货价
     */
    private BigDecimal supplyPrice;

    /**
     * 库存数
     */
    private Integer stockNumber;

    /**
     * 商品条码
     */
    private String barcode;

    /**
     * 排序
     */
    private Integer sortNumber;

    /**
     * 入驻企业ID
     */
    private Long settledCompanyId;

    /**
     * 老规格码
     */
    private String oldSpecCode;

    /**
     * 老SKU编码码
     */
    private String oldSkuCode;
    /**
     * 产品库存
     */
    @TableField(exist = false)
    private Integer inventoryNumber;

    @TableField(exist = false)
    private String companyName;

    /**
     * 状态:up(0,上架);down(1,下架)
     */
    public enum Status implements IEnum<Integer> {

        /**
         * 上架
         */
        up(0,"上架"),
        /**
         * 下架
         */
        down(1,"下架");

        private int code;
        private String desc;

        Status(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 状态
     */
//    private ProductDetail.Status status;

    /**
     * 状态描述
     */
    /*@TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        return status == null ? null : status.getDesc();
    }*/

    public enum IsSyns implements IEnum<Integer> {

        /**
         * 未同步
         */
        no(0,"未同步"),
        /**
         * 已同步
         */
        yes(1,"已同步");

        private int code;
        private String desc;

        IsSyns(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }
    private ProductDetail.IsSyns isSyns;

    @TableField(exist = false)
    private String isSynsDesc;
    public enum DataSourceType implements IEnum<Integer> {

        /**
         * 自采
         */
        oneself(0,"自采"),
        /**
         * 平台
         */
        platform(1,"平台"),
        /**
         * 本地
         */
        local(2,"本地");

        private int code;
        private String desc;

        DataSourceType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static DataSourceType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (DataSourceType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }

    }

    /**
     * 产品类型ID
     */
    private Long productTypeId;

    /**
     * 产品类型名称
     */
    @TableField(exist = false)
    private String productTypeName;

    /**
     * 产品分类ID
     */
    private Long productCategoryId;

    /**
     * 产品分类名称
     */
    @TableField(exist = false)
    private String categoryName;

    /**
     * 单位ID
     */
    private Long unitId;

    /**
     * 单位名称
     */
    @TableField(exist = false)
    private String unitName;

    /**
     * 品牌ID
     */
    private Long brandId;

    private Long idPlatform;

    /**
     * 品牌名称
     */
    @TableField(exist = false)
    private String brandName;

    /**
     * 计价方式:piece(0,按件);weight(1,按重量)'
     */
    public enum PricingMethod implements IEnum<Integer> {

        /**
         * 按件
         */
        piece(0,"按件"),
        /**
         * 按重量
         */
        weight(1,"按重量");

        private int code;
        private String desc;

        PricingMethod(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static PricingMethod jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (PricingMethod item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    /**
     * 计价方式
     */
    private ProductDetail.PricingMethod pricingMethod;

    /**
     * 计价方式描述
     */
    @TableField(exist = false)
    private String pricingMethodDesc;

    public String getPricingMethodDesc() {
        return pricingMethod == null ? null : pricingMethod.getDesc();
    }

    /**
     * 同步时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime synsTime;

    /**
     * 用于区分云端云仓手动添加产品
     */
    private String skuCodeAs;

    /**
     * 包装id
     */
    private Long packId;

    /**
     * 寿命单位  1：小时/ 2：次数
     */
    private  LifeUnit  lifeUnit;
    /**
     * 1：分钟/ 2：个数
     */
    public enum LifeUnit implements IEnum<Integer> {

        /**
         * 分钟
         */
        minute(1,"分钟"),
        /**
         * 个数
         */
        number(2,"个数");

        private int code;
        private String desc;

        LifeUnit(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static LifeUnit jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (LifeUnit item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    /**
     * 使用寿命
     */
    private Integer lifeSpan;

    /**
     * 安全库存数量
     */
    private Integer warningQuantity;

    /**
     * 是否来源简版  0  不是   1 是
     */
    private Integer simplify;

    @TableField(exist = false)
    private String productUniqCode;

    /**
     * 归还时长阈值
     */
    private Integer returnThreshold;

    /**
     * 呆滞时长阈值
     */
    private Integer lethargyThreshold;


    public enum InventoryUnitType implements IEnum<Integer> {

        /**
         * 重量
         */
        weight(1,"重量"),
        /**
         * 数量
         */
        quantity(2,"数量");

        private int code;
        private String desc;

        InventoryUnitType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static InventoryUnitType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (InventoryUnitType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }


    private InventoryUnitType inventoryUnitType;

    private Boolean returnType;

    public enum StorageKnifeType implements IEnum<Integer> {

        /**
         * 存刀柜
         */
        storage(0,"存刀柜"),
        /**
         * 售刀柜
         */
        scraper(1,"售刀柜");

        private int code;
        private String desc;

        StorageKnifeType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static StorageKnifeType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (StorageKnifeType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    private StorageKnifeType storageKnifeType;

    /**
     * 供应商id
     */
    private Long supplierId;


    @TableField(exist = false)
    private Integer unitRate;

    /**
     * 基础单位单价
     */
    private BigDecimal basePrice;

    /**
     * 基础单位数量
     */
    private Integer baseQuantity;
}
